//
//  AddUserTFCell.swift
//  koolcar
//
//  Created by xiantian on 2023/9/20.
//

import UIKit

class AddUserTFCell: UITableViewCell {
    var titleLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 1
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        return tempLab
    }()
    var textField: UITextField!
    var msgLab: UILabel!
    var rightView: UIView? {
        didSet {
            if let right = rightView {
                self.contentView.addSubview(right)
                right.snp.makeConstraints { make in
                    make.right.equalTo(-14)
                    make.centerY.equalTo(self.textField.snp.centerY)
                    make.width.equalTo(right.frame.size.width)
                    make.height.equalTo(right.frame.size.height)
                }
            }
            self.updateConstraints()
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(titleLab)
        
        textField = UITextField(frame: CGRect.zero)
        textField.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        textField.textColor = Theme.titleLabColor
        textField.layer.cornerRadius = 8
        textField.layer.borderWidth = 1
        textField.layer.borderColor = Theme.tfBorderColor.cgColor
        textField.layer.masksToBounds = true
        textField.clearButtonMode = .whileEditing
        textField.returnKeyType = .done
        textField.keyboardType = .default
        contentView.addSubview(textField)
        
        let leftView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 10, height: 10))
        textField.leftView = leftView
        textField.leftViewMode = .always
     
        msgLab = UILabel()
        msgLab.textColor = Theme.redColor
        msgLab.backgroundColor = UIColor.clear
        msgLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 11)
        msgLab.numberOfLines = 0
        msgLab.lineBreakMode = .byTruncatingTail
        msgLab.textAlignment = .left
        contentView.addSubview(msgLab)
        
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(0)
            make.height.greaterThanOrEqualTo(0)
            make.right.equalTo(-14)
        }
        
        textField.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.top.equalTo(titleLab.snp.bottom).offset(6)
            make.height.greaterThanOrEqualTo(44)
        }
        
        msgLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.top.equalTo(textField.snp.bottom).offset(6)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalTo(-14)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setAddUserTFCell(){
    }
    
    func showTopTitleLab(txt: String){
        self.titleLab.text = txt
        self.titleLab.snp.updateConstraints { make in
            make.height.greaterThanOrEqualTo(20)
        }
        self.updateConstraints()
    }
    
}
